package com.example.controller.ex;

import com.example.service.ex.*;
import com.example.service.ex.CategoryException.CategoryNotException;
import com.example.service.ex.CategoryException.DishException;
import com.example.service.ex.CategoryException.SetmealException;
import com.example.service.ex.EmployeeException.*;
import com.example.utils.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//项目的异常处理器
@RestControllerAdvice
public class ProjectExceptionAdvice {
    @ExceptionHandler(ServiceException.class)
    public R doException(Throwable e){
        R r = new R();
        if (e instanceof UserNameNotFondException){
            r.setCode(0);
            r.setMsg(e.getMessage());
        }else if (e instanceof PasswordNotFondException){
            r.setCode(0);
            r.setMsg(e.getMessage());
        }else if (e instanceof UserNotFondException){
            r.setCode(0);
            r.setMsg(e.getMessage());
        }else if (e instanceof UsernameException){
            r.setCode(0);
            r.setMsg(e.getMessage());
        }else if (e instanceof InsertException){
            r.setCode(0);
            r.setMsg(e.getMessage());
        }else if (e instanceof UpdateException){
            r.setCode(0);
            r.setMsg(e.getMessage());
        }else if (e instanceof CategoryNotException){
            r.setCode(0);
            r.setMsg(e.getMessage());
        }else if (e instanceof DishException){
            r.setCode(0);
            r.setMsg(e.getMessage());
        }else if (e instanceof SetmealException){
            r.setCode(0);
            r.setMsg(e.getMessage());
        }else if (e instanceof DeleteException){
            r.setCode(0);
            r.setMsg(e.getMessage());
        }else if (e instanceof CountException){
            r.setCode(0);
            r.setMsg(e.getMessage());
        }else if (e instanceof CustomException){
            r.setCode(0);
            r.setMsg(e.getMessage());
        }
        return r;
    }
}
